 package com.zz.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zz.entity.Product;
import com.zz.entity.Ware;
import com.zz.service.ProductService;

@RestController
@RequestMapping("product")
public class ProductController {
	@Resource
	ProductService productService;
//	显示所有商品信息并进行分页
	@RequestMapping("getall")
	public Page<Object[]> getall(HttpServletRequest request){
		String startpage=request.getParameter("start");
		return productService.getall(startpage, "5");
	}
//	根据id修改商品信息
	@RequestMapping("updatepdt")
	public Integer updatepdt(HttpServletRequest request){
		String type=request.getParameter("type");
		String location=request.getParameter("location");
		String num=request.getParameter("num");
		
		String warename=request.getParameter("ware");
		
		Ware ware=productService.findwareByname(warename);
		String wareid=ware.getId();
	
		String id=request.getParameter("id");
		return productService.updatepdt(type, location, Integer.parseInt(num),wareid,id);
	}
	
	//根据id删除商品
	@RequestMapping("deletepdt")
		public int deletepdt(HttpServletRequest request){
			return productService.deletepdt(request.getParameter("pid"));
		}
	
	//根据名字查询商品信息
	@RequestMapping("findByName")
		public Page<Object[]> findByName(HttpServletRequest request){
			String startpage=request.getParameter("start");
			return productService.findByName(request.getParameter("selectname"),startpage,"5");
		}
}
